
var ReminderCollection = Backbone.Collection.extend({
    fetch:function(){
        $.ajax({
            type:'POST',
            dataType:'json',
            url:'json/reminder.json',
            success:function(res){
                var list = res.list;
                var config = {
                    'c1':{
                        id:0,
                        label : '新股中签提醒',
                        img : 'images/actx_07.png',
                        type:1,
                        status:'0'
                    },
                    'c2':{
                        id:1,
                        label : '产品到期提醒',
                        img : 'images/actx_11.png',
                        type:2,
                        status:'0'
                    },
                    'c3':{
                        id:2,
                        label : '交易确认提醒',
                        img : 'images/actx_13.png',
                        type:3,
                        status:'0'
                    },
                    'c4':{
                        id:3,
                        label : '持仓股重要公告提醒',
                        img : 'images/actx_16.png',
                        type:4,
                        status:'0'
                    },
                    'c5':{
                        id:4,
                        label : '资金变动提醒',
                        img : 'images/actx_18.png',
                        type:5,
                        status:'0'
                    }
                };
                for(var l in list) {
                    var cf = config['c'+list[l].type];
                    cf.status = list[l].status;
                    cf.id = list[l].id;
                }

                for(var c in config){
                    reminderCollection.add(new Backbone.Model().set(config[c]));
                }
            }
        });
    },
    update:function(rid){
        var getModel = reminderCollection.get(rid);
        var status = getModel.get('status');
        status = status == '0' ? '1' : ((status == '1') ? '0':'1');
        $.ajax({
            type:'POST',
            dataType:'json',
            url:'json/commit.json',
            data:{rid:rid ,status:status},
            success:function(res){
               if(res.status=='0'){
                   getModel.set({status:status});
                   reminderCollection.add(getModel,{merge: true});
               }else{
                   new popup({content:"操作失败，"+res.errMsg});
               }
            }
        });
    }
});
var reminderCollection = new ReminderCollection;